<?php

namespace Database\Seeders;
use App\Models\TcmPrescriptionDetail;
use Illuminate\Database\Seeder;

class TcmPrescriptionSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        if (TcmPrescriptionDetail::count() == 0) {
            $sql = file_get_contents(__DIR__ .'/../tcm_prescription_detail.sql');

            $statements = collect(array_filter(array_map('trim', explode(';', $sql))));

            // 一次运行1000条插入语句
            $statements->chunk(1000)->each(function($sqls) {

                $sql = $sqls->implode(";") . ';';

                \DB::unprepared($sql);

                usleep(250);
            });
        }
    }
}
